|
1
|
|
|
import execa from 'execa' |
|
2
|
|
|
import {existsSync} from 'fs' |
|
3
|
|
|
import {PHP_EXTENSIONS} from './extensions' |
|
4
|
|
|
|
|
5
|
|
|
class Pecl { |
|
6
|
|
|
/** |
|
7
|
|
|
* Get the path of the PHP ini currently used by PECL. |
|
8
|
|
|
*/ |
|
9
|
|
|
static getPhpIni = async (): Promise<string> => { |
|
10
|
|
|
const peclIni = await execa('pecl', ['config-get', 'php_ini']) |
|
11
|
|
|
const peclIniPath = peclIni.stdout.replace('\n', '') |
|
12
|
|
|
|
|
13
|
|
|
if (existsSync(peclIniPath)) |
|
14
|
|
|
return peclIniPath |
|
15
|
|
|
|
|
16
|
|
|
const phpIni = await execa('php', ['-i', '|', 'grep', 'php.ini']) |
|
17
|
|
|
|
|
18
|
|
|
const matches = phpIni.stdout.match(/Path => ([^\s]*)/) |
|
19
|
|
|
|
|
20
|
|
|
if (!matches || matches.length <= 0) |
|
21
|
|
|
throw new Error('Unable to find php.ini.') |
|
22
|
|
|
|
|
23
|
|
|
return `${matches[1].trim()}/php.ini` |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Get the path of the extension directory currently used by PECL. |
|
28
|
|
|
*/ |
|
29
|
|
|
static getExtensionDirectory = async (): Promise<string> => { |
|
30
|
|
|
const {stdout} = await execa('pecl', ['config-get', 'ext_dir']) |
|
31
|
|
|
let directory = stdout.replace('\n', '').trim() |
|
32
|
|
|
|
|
33
|
|
|
if (directory.indexOf('/Cellar/') !== -1) |
|
34
|
|
|
directory = directory.replace('/lib/php/', '/pecl/') |
|
35
|
|
|
|
|
36
|
|
|
return directory |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Install all extensions supported by Jale. Set optionals to true to also include optional extensions. |
|
41
|
|
|
* |
|
42
|
|
|
* @param optionals |
|
43
|
|
|
*/ |
|
44
|
|
|
static installExtensions = async (optionals: boolean = false) => { |
|
45
|
|
|
console.log('Installing PECL extensions') |
|
46
|
|
|
|
|
47
|
|
|
for (const extension of PHP_EXTENSIONS) { |
|
48
|
|
|
const ext = new extension |
|
49
|
|
|
if (!optionals && !ext.default) |
|
50
|
|
|
continue |
|
51
|
|
|
|
|
52
|
|
|
await ext.install() |
|
53
|
|
|
await ext.enable() |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Uninstall all extensions supported by Jale. Set optionals to true to also include optional extensions. |
|
59
|
|
|
* |
|
60
|
|
|
* @param optionals |
|
61
|
|
|
*/ |
|
62
|
|
|
static uninstallExtensions = async (optionals: boolean = false) => { |
|
63
|
|
|
console.log('Uninstalling PECL extensions') |
|
64
|
|
|
|
|
65
|
|
|
for (const extension of PHP_EXTENSIONS) { |
|
66
|
|
|
const ext = new extension |
|
67
|
|
|
if (!optionals && !ext.default) |
|
68
|
|
|
continue |
|
69
|
|
|
|
|
70
|
|
|
await ext.uninstall() |
|
71
|
|
|
await ext.disable() |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
export default Pecl |